package chapter02

object Test09_Fibonaqi {
  def main(args: Array[String]): Unit = {
    //1 1 2 3 5 8 13 f(n) = f(n-1)+f(n-2)
    def f(n:Int):Int={
      if(n==1){
        return 1
      }
      if(n==2){
        return 1
      }
      f(n-1)+f(n-2)
    }
    def sum(n:Int):Int={
      var c = 0
      for(i<-1 to n){
        c += f(i)
        println(s"第${i}项的值为："+f(i))
      }
      c
    }
    println("总和为："+sum(10))
  }
}
